<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
<title>Automatic evaluation rules of symbolic expressions</title>
<meta name="authors" content="Pearu Peterson &lt;pearu.peterson AT gmail DOT com&gt;  Fredrik Johansson" />
<style type="text/css">

/*
:Author: Pearu Peterson
:Contact: pearu.peterson AT gmail DOT com
:Copyright: This stylesheet has been placed in the public domain.

Stylesheet for use with Docutils.
*/

@import url(html4css1.css);

/* Your customizations go here.  For example: */

body {
    margin:0px;
    padding:25px;
    background-color: #ccc;
    font-size: 13px; font-family: arial, sans-serif;
    line-height:1.5em;
}

div.document {
    max-width: 700px;
    color: #000;
    background-color: #fff;
    padding:25px;
    border:5px solid #ddd;
}

div.sidebar {
  margin-left: 1em ;
  border: medium outset ;
  padding: 1em ;
  background-color: #ffffee ;
  width: 40% ;
  float: right ;
  clear: right }

div.sidebar p.rubric {
  font-family: sans-serif ;
  font-size: medium }

p.sidebar-title {
  font-family: sans-serif ;
  font-weight: bold ;
  font-size: larger }

p.sidebar-subtitle {
  font-family: sans-serif ;
  font-weight: bold }

pre, tt {
  font-family: consolas, lucida console, courier new, monospace;
  color: #000080 ;
}

pre.literal-block, pre.doctest-block {
  line-height:1.3em;
  border-top:1px solid #ccc;
  border-bottom:1px solid #ccc;
  background-color:#f0f0f0;
  color: #000080 ;
}

div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
  margin: 2em ;
  border: medium outset ;
  padding: 0.5em;
  background-color: #fffacd;  
}

div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
  font-weight: bold ;
  font-family: sans-serif }

div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
  color: red ;
  font-weight: bold ;
  font-family: sans-serif }

</style>
</head>
<body>
<div class="document" id="automatic-evaluation-rules-of-symbolic-expressions">
<h1 class="title">Automatic evaluation rules of symbolic expressions</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr><th class="docinfo-name">Authors:</th>
<td>Pearu Peterson &lt;pearu.peterson AT gmail DOT com&gt;
<br />Fredrik Johansson</td></tr>
<tr class="field"><th class="docinfo-name">Created:</th><td class="field-body">February 2008</td>
</tr>
</tbody>
</table>
<!-- -*- rest -*- -->
<div class="sidebar">
<p class="first sidebar-title">Table of contents</p>
<div class="contents local last topic">
<ul class="auto-toc simple">
<li><a class="reference" href="#introduction" id="id4" name="id4">1&nbsp;&nbsp;&nbsp;Introduction</a></li>
<li><a class="reference" href="#commutative-ring-operations" id="id5" name="id5">2&nbsp;&nbsp;&nbsp;Commutative ring operations</a><ul class="auto-toc">
<li><a class="reference" href="#operands" id="id6" name="id6">2.1&nbsp;&nbsp;&nbsp;Operands</a></li>
<li><a class="reference" href="#operations" id="id7" name="id7">2.2&nbsp;&nbsp;&nbsp;Operations</a></li>
</ul>
</li>
<li><a class="reference" href="#extended-numbers" id="id8" name="id8">3&nbsp;&nbsp;&nbsp;Extended numbers</a></li>
<li><a class="reference" href="#function-evaluations" id="id9" name="id9">4&nbsp;&nbsp;&nbsp;Function evaluations</a><ul class="auto-toc">
<li><a class="reference" href="#general-rules" id="id10" name="id10">4.1&nbsp;&nbsp;&nbsp;General rules</a></li>
<li><a class="reference" href="#exponentials" id="id11" name="id11">4.2&nbsp;&nbsp;&nbsp;Exponentials</a></li>
<li><a class="reference" href="#logarithms" id="id12" name="id12">4.3&nbsp;&nbsp;&nbsp;Logarithms</a></li>
<li><a class="reference" href="#trigonometric-functions" id="id13" name="id13">4.4&nbsp;&nbsp;&nbsp;Trigonometric functions</a></li>
</ul>
</li>
<li><a class="reference" href="#references" id="id14" name="id14">5&nbsp;&nbsp;&nbsp;References</a></li>
</ul>
</div>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id4" id="introduction" name="introduction">1&nbsp;&nbsp;&nbsp;Introduction</a></h1>
<p>This document gathers rules that are applied automatically when
performing operations with symbolic expressions.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id5" id="commutative-ring-operations" name="commutative-ring-operations">2&nbsp;&nbsp;&nbsp;Commutative ring operations</a></h1>
<div class="section">
<h2><a class="toc-backref" href="#id6" id="operands" name="operands">2.1&nbsp;&nbsp;&nbsp;Operands</a></h2>
<p>In commutative ring operations, four types of operands are possible:</p>
<blockquote>
<ul class="simple">
<li>numbers, see examples below;</li>
<li>sums, e.g. <tt class="docutils literal"><span class="pre">3+x</span></tt>, <tt class="docutils literal"><span class="pre">-1/2+x+y</span></tt>;</li>
<li>products, e.g. <tt class="docutils literal"><span class="pre">3*x</span></tt>, <tt class="docutils literal"><span class="pre">x**2</span> <span class="pre">*</span> <span class="pre">z</span></tt>;</li>
<li>symbols, e.g. <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">sin(x+z**2)</span></tt>.</li>
</ul>
</blockquote>
<p>Depending on a particular ring, numbers can be</p>
<blockquote>
<ul class="simple">
<li>integers, e.g. <tt class="docutils literal"><span class="pre">-4</span></tt>, <tt class="docutils literal"><span class="pre">0</span></tt>, <tt class="docutils literal"><span class="pre">1</span></tt>;</li>
<li>fractions, e.g. <tt class="docutils literal"><span class="pre">1/2</span></tt>, <tt class="docutils literal"><span class="pre">-3/4</span></tt>;</li>
<li>complex numbers, e.g. <tt class="docutils literal"><span class="pre">2+3/4*I</span></tt>, <tt class="docutils literal"><span class="pre">-4*I</span></tt>;</li>
<li>floating point numbers, e.g. <tt class="docutils literal"><span class="pre">1.2</span></tt>, <tt class="docutils literal"><span class="pre">-3.14</span></tt>;</li>
<li>extended numbers, e.g. <tt class="docutils literal"><span class="pre">+oo</span></tt>, <tt class="docutils literal"><span class="pre">-oo</span></tt>, <tt class="docutils literal"><span class="pre">zoo</span></tt>, <tt class="docutils literal"><span class="pre">undefined</span></tt>;</li>
</ul>
</blockquote>
<p>where real and imaginary parts of complex numbers can be integers,
fractions, or floating point numbers.</p>
<div class="admonition-metarule-1 admonition">
<p class="first admonition-title">Metarule 1</p>
<p class="last">Any rule containing symbols, should remain valid when the symbols
are replaced by numbers.</p>
</div>
<div class="section">
<h3><a id="notes-on-extended-numbers" name="notes-on-extended-numbers">2.1.1&nbsp;&nbsp;&nbsp;Notes on extended numbers</a></h3>
<p>Expressions containing extended numbers require special rules as
distributivity laws are not valid for extended numbers. An extended
number is defined as a quantity that has infinite or undefined
magnitude and has specified or undefined direction in the complex
plane. See below for detailed information.</p>
</div>
<div class="section">
<h3><a id="notes-on-floating-point-numbers" name="notes-on-floating-point-numbers">2.1.2&nbsp;&nbsp;&nbsp;Notes on floating point numbers</a></h3>
<p>Note that the distributivity law is not strictly valid also for
operations with floating point numbers but in the following we assume
it to hold for simplicity.</p>
</div>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id7" id="operations" name="operations">2.2&nbsp;&nbsp;&nbsp;Operations</a></h2>
<p>In the following we consider three kinds of operations with operands:</p>
<blockquote>
<ul class="simple">
<li>addition: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">y</span></tt></li>
<li>multiplication: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">y</span></tt></li>
<li>exponentiation: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">**</span> <span class="pre">y</span></tt></li>
</ul>
</blockquote>
<p>These operations can be used to define other operations</p>
<blockquote>
<ul class="simple">
<li>negation: <tt class="docutils literal"><span class="pre">-x</span> <span class="pre">==</span> <span class="pre">x</span> <span class="pre">*</span> <span class="pre">(-1)</span></tt></li>
<li>subtraction: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">y</span> <span class="pre">==</span> <span class="pre">x</span> <span class="pre">+</span> <span class="pre">(-y)</span></tt></li>
<li>division: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span> <span class="pre">==</span> <span class="pre">x</span> <span class="pre">*</span> <span class="pre">y**(-1)</span></tt></li>
</ul>
</blockquote>
<p>and hence there is no need to write rules for these operations.</p>
<div class="admonition-rule-1-associativity admonition">
<p class="first admonition-title">Rule 1: associativity</p>
<p>In <a class="reference" href="http://en.wikipedia.org/wiki/Associative">associative</a> operations all parenthesis are eliminated
(expressions are <em>flattened</em> and suboperands of operands are stored
in the same set-like data structure).</p>
<p>For example:</p>
<pre class="last literal-block">
x + (y + z) -&gt; x + y + z
(x + y) + z -&gt; x + y + z
x * (y * z) -&gt; x * y * z
(x * y) * z -&gt; x * y * z
</pre>
</div>
<div class="admonition-rule-2-commutativity admonition">
<p class="first admonition-title">Rule 2: commutativity</p>
<p>In <a class="reference" href="http://en.wikipedia.org/wiki/Commutativity">commutative</a> operations the order of operands is insignificant
(operands are stored in an unordered set-like data structure).</p>
<p>For example:</p>
<pre class="last literal-block">
x + y == y + x
x * y == y * x
</pre>
</div>
<div class="admonition-rule-3-collecting-equal-expressions admonition">
<p class="first admonition-title">Rule 3: collecting equal expressions</p>
<p>In commutative operations <em>equal</em> expressions are collected. The
equality is defined as an <em>equality between data structures</em> which
may not be equivalent to the notion of <em>mathematical equality</em>.</p>
<p>For example:</p>
<pre class="last literal-block">
x + x -&gt; 2*x
x * x -&gt; x**2
</pre>
</div>
<div class="admonition-rule-4-operations-with-zero admonition">
<p class="first admonition-title">Rule 4: operations with zero.</p>
<p>Multiplication by zero is zero only when a non-zero operand does not
contain extended numbers explicitly.</p>
<p>For example:</p>
<pre class="literal-block">
0 * x -&gt; 0
</pre>
<p>Division a non-zero number by zero is infinity with undefined direction:</p>
<pre class="literal-block">
1/0 -&gt; zoo
0/0 -&gt; undefined
</pre>
<p>Exponentiation by zero results one.</p>
<p>For example:</p>
<pre class="last literal-block">
x**0 -&gt; 1
oo**0 -&gt; 1
</pre>
</div>
<div class="admonition-rule-5-distributivity admonition">
<p class="first admonition-title">Rule 5: distributivity</p>
<p><a class="reference" href="http://en.wikipedia.org/wiki/Distributivity">Distributivity</a> law of multiplication over addition is applied
only when a sum is multiplied by a number that is not an extended
number.</p>
<p>For example:</p>
<pre class="last literal-block">
3*(x + y) -&gt; 3*x + 3*y
(3 + x)/2 -&gt; 3/2 + 1/2*x
oo*(2 + x) -&gt; oo*(2 + x)
</pre>
</div>
<p>All number sets (integers, rationals, complex numbers) are closed with
respect to addition and multiplication operations.  Hence:</p>
<div class="admonition-rule-6-additing-and-multiplying-numbers admonition">
<p class="first admonition-title">Rule 6: additing and multiplying numbers</p>
<p class="last">Addition and multiplication operations with numbers always result in
a number.</p>
</div>
<p>Exponentiation operation with numbers are evaluated to a number when
possible. In case of algebraic numbers, suppresed evaluation may be
carried out. For example:</p>
<pre class="literal-block">
2**3 -&gt; 8
2**(-3) -&gt; 1/8
4**(1/2) -&gt; 2
8**(1/2) -&gt; 2*2**(1/2)
</pre>
<div class="section">
<h3><a id="integer-powers" name="integer-powers">2.2.1&nbsp;&nbsp;&nbsp;Integer powers</a></h3>
<div class="admonition-rule-7-m-n-for-a-number-m-and-integer-n admonition">
<p class="first admonition-title">Rule 7: <tt class="docutils literal"><span class="pre">m</span> <span class="pre">**</span> <span class="pre">n</span></tt> for a number <tt class="docutils literal"><span class="pre">m</span></tt> and integer <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
<p>If <tt class="docutils literal"><span class="pre">n</span></tt> is <tt class="docutils literal"><span class="pre">0</span></tt> then the result is <tt class="docutils literal"><span class="pre">1</span></tt>.</p>
<p>If <tt class="docutils literal"><span class="pre">n</span></tt> is positive then the result is a number. Different
algorithms are possible for cases where <tt class="docutils literal"><span class="pre">m</span></tt> is integer, or
fraction, or floating point number, or complex number, or purely
imaginary complex number.</p>
<p class="last">If <tt class="docutils literal"><span class="pre">n</span></tt> is negative then the result is <tt class="docutils literal"><span class="pre">1/(m**(-n))</span></tt> (or
<tt class="docutils literal"><span class="pre">(1/m)**(-n)</span></tt>).</p>
</div>
<div class="admonition-rule-8-w-z-n-for-symbols-w-z-and-integer-n admonition">
<p class="first admonition-title">Rule 8: <tt class="docutils literal"><span class="pre">(w*z)</span> <span class="pre">**</span> <span class="pre">n</span></tt> for symbols <tt class="docutils literal"><span class="pre">w</span></tt>, <tt class="docutils literal"><span class="pre">z</span></tt>, and integer <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
<p class="last">The result is <tt class="docutils literal"><span class="pre">w**n</span> <span class="pre">*</span> <span class="pre">z**n</span></tt>.</p>
</div>
<div class="admonition-rule-9-w-z-n-for-symbols-w-z-and-integer-n admonition">
<p class="first admonition-title">Rule 9: <tt class="docutils literal"><span class="pre">(w**z)</span> <span class="pre">**</span> <span class="pre">n</span></tt> for symbols <tt class="docutils literal"><span class="pre">w</span></tt>, <tt class="docutils literal"><span class="pre">z</span></tt>, and integer <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
<p class="last">The result is <tt class="docutils literal"><span class="pre">w**(n*z)</span></tt>.</p>
</div>
</div>
<div class="section">
<h3><a id="fraction-powers" name="fraction-powers">2.2.2&nbsp;&nbsp;&nbsp;Fraction powers</a></h3>
<div class="admonition-rule-11-m-1-q-for-integers-m-q-0 admonition">
<p class="first admonition-title">Rule 11: <tt class="docutils literal"><span class="pre">m</span> <span class="pre">**</span> <span class="pre">(1/q)</span></tt> for integers <tt class="docutils literal"><span class="pre">m</span></tt>, <tt class="docutils literal"><span class="pre">q&gt;0</span></tt>.</p>
<p>If <tt class="docutils literal"><span class="pre">m</span></tt> is positive then the result is a product of algebraic numbers.</p>
<p class="last">If <tt class="docutils literal"><span class="pre">m</span></tt> is negative then the result is <tt class="docutils literal"><span class="pre">(-1)**(1/q)</span> <span class="pre">*</span> <span class="pre">(-m)**(1/q)</span></tt></p>
</div>
<div class="admonition-rule-12-m-p-q-for-integers-m-p-1-q-0 admonition">
<p class="first admonition-title">Rule 12: <tt class="docutils literal"><span class="pre">m</span> <span class="pre">**</span> <span class="pre">(p/q)</span></tt> for integers <tt class="docutils literal"><span class="pre">m</span></tt>, <tt class="docutils literal"><span class="pre">p!=1</span></tt>, <tt class="docutils literal"><span class="pre">q&gt;0</span></tt>.</p>
<p class="last">The result is evaluated result of <tt class="docutils literal"><span class="pre">(m</span> <span class="pre">**</span> <span class="pre">(1/q))**p</span></tt>.</p>
</div>
</div>
</div>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id8" id="extended-numbers" name="extended-numbers">3&nbsp;&nbsp;&nbsp;Extended numbers</a></h1>
<p>See also <a class="reference" href="http://code.google.com/p/sympycore/wiki/ExtendedNumbers">http://code.google.com/p/sympycore/wiki/ExtendedNumbers</a>.</p>
<p>The reason why distributivity law is not used in case of extended
numbers, such as infinities, is that it might lead to undefined
results that otherwise would be defined.  For example, if <tt class="docutils literal"><span class="pre">x=-1</span></tt>
then:</p>
<pre class="literal-block">
oo*(2 + x) -&gt; oo*1 -&gt; oo
</pre>
<p>but</p>
<pre class="literal-block">
oo*(2 + x) -&gt; oo + oo*x -&gt; oo + oo*(-1) -&gt; oo - oo -&gt; undefined
</pre>
<p>An extended number is defined as a quantity that has infinite or
undefined magnitude and has specified or undefined direction in the
complex plane.</p>
<p>Infinity with direction <tt class="docutils literal"><span class="pre">theta</span> <span class="pre">=</span> <span class="pre">Arg(direction)</span></tt> can be defined as
follows:</p>
<div class="admonition-definition-infinity-with-direction admonition">
<p class="first admonition-title">Definition: infinity with direction</p>
<pre class="literal-block">
oo(direction) =  lim     r * direction
                r -&gt; oo
</pre>
<p class="last">where <tt class="docutils literal"><span class="pre">direction</span></tt> is a complex number.</p>
</div>
<div class="admonition-definition-quantity-with-undefined-magnitude admonition">
<p class="first admonition-title">Definition: quantity with undefined magnitude.</p>
<p class="last">A quantity with undefined magnitude and undefined direction is defined as <tt class="docutils literal"><span class="pre">oo(0)</span></tt>.</p>
</div>
<div class="admonition-definition-projective-infinity admonition">
<p class="first admonition-title">Definition: projective infinity.</p>
<p class="last">Infinity with undefined direction is defined as <tt class="docutils literal"><span class="pre">oo(undefined)</span></tt>.</p>
</div>
<p>The following notation is used:</p>
<pre class="literal-block">
+oo = oo(1)
-oo = oo(-1)
zoo = oo(oo(0))
</pre>
<p>An operation <tt class="docutils literal"><span class="pre">&lt;op&gt;</span></tt> with an infinity and a finite number is defined
as follows:</p>
<div class="admonition-definition-operations-with-finite-numbers admonition">
<p class="first admonition-title">Definition: operations with finite numbers</p>
<pre class="last literal-block">
oo(direction) &lt;op&gt; number =   lim    r * direction &lt;op&gt; number
                            r -&gt; oo
</pre>
</div>
<p>An operation <tt class="docutils literal"><span class="pre">&lt;op&gt;</span></tt> with two infinities with different directions is
defined as follows:</p>
<div class="admonition-definition-operations-with-infinite-numbers admonition">
<p class="first admonition-title">Definition: operations with infinite numbers</p>
<pre class="literal-block">
oo(dir1) &lt;op&gt; oo(dir2) =   lim      r1 * dir1 &lt;op&gt; r2 * dir2
                        r1, r2 -&gt; oo
</pre>
<p>where the limit processes <tt class="docutils literal"><span class="pre">r1-&gt;oo</span></tt> and <tt class="docutils literal"><span class="pre">r2-&gt;oo</span></tt> are independent.</p>
<p class="last">If <tt class="docutils literal"><span class="pre">lim(r1-&gt;oo,</span> <span class="pre">r2-&gt;oo)</span></tt> is different from <tt class="docutils literal"><span class="pre">lim(r2-&gt;oo,</span> <span class="pre">r1-&gt;oo)</span></tt>
then the result is defined as <tt class="docutils literal"><span class="pre">undefined</span></tt>.</p>
</div>
<div class="admonition-addition-with-infinities admonition">
<p class="first admonition-title">Addition with infinities</p>
<pre class="last literal-block">
oo(x) + oo(y) -&gt; oo(EqualArg(x,y)*x)
oo(x) + z     -&gt; oo((1+IsUnbounded(z)*(EqualArg(x,y)-1))*x)
</pre>
</div>
<div class="admonition-multiplication-with-infinities admonition">
<p class="first admonition-title">Multiplication with infinities</p>
<pre class="last literal-block">
oo(x) * oo(y) -&gt; oo(x*y)
oo(x) * z     -&gt; oo(x*z)
</pre>
</div>
<div class="admonition-dividing-by-infinity admonition">
<p class="first admonition-title">Dividing by infinity</p>
<pre class="last literal-block">
1/oo(x)       -&gt; 0 for nonzero x
</pre>
</div>
<div class="admonition-exponentiation-with-infinities admonition">
<p class="first admonition-title">Exponentiation with infinities</p>
<pre class="last literal-block">
oo(x) ** 0     -&gt; 1
1 ** oo(x)     -&gt; 1
oo(x) ** oo(y) -&gt; 0                 if y &lt; 0
oo(x) ** oo(y) -&gt; oo(IsPositive(x)) if y &gt; 0
oo(x) ** z     -&gt; 0 if z &lt; 0
oo(x) ** z     -&gt; oo(x**z) if z&gt;0
z ** oo(x)     -&gt; (z**x) ** oo(1)
</pre>
</div>
<p>TODO: define more rules for defined results.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id9" id="function-evaluations" name="function-evaluations">4&nbsp;&nbsp;&nbsp;Function evaluations</a></h1>
<div class="section">
<h2><a class="toc-backref" href="#id10" id="general-rules" name="general-rules">4.1&nbsp;&nbsp;&nbsp;General rules</a></h2>
<div class="admonition-function-evaluation admonition">
<p class="first admonition-title">Function evaluation.</p>
<p class="last">A function should automatically evaluate back to a number when given
an input for which it assumes a rational or complex rational
value.</p>
</div>
<p>An exception to this rule can be made if the computation required to
produce the number is extremely time-consuming.</p>
<div class="admonition-floating-point-function-evaluation admonition">
<p class="first admonition-title">Floating-point function evaluation.</p>
<p class="last">Given a floating-point number <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">f(x)</span></tt> should return a
floating-point approximation.</p>
</div>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id11" id="exponentials" name="exponentials">4.2&nbsp;&nbsp;&nbsp;Exponentials</a></h2>
<p><tt class="docutils literal"><span class="pre">exp(x)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">E**x</span></tt>, and implemented as a simple
wrapper for this operation.</p>
<p>Likewise, <tt class="docutils literal"><span class="pre">sqrt(x)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">x**(1/2)</span></tt>.</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id12" id="logarithms" name="logarithms">4.3&nbsp;&nbsp;&nbsp;Logarithms</a></h2>
<p><tt class="docutils literal"><span class="pre">log(x,b)</span></tt> is defined as <tt class="docutils literal"><span class="pre">log(x)/log(b)</span></tt>. <tt class="docutils literal"><span class="pre">log(x)</span></tt> denotes the
natural logarithm with base <tt class="docutils literal"><span class="pre">b</span></tt> = <tt class="docutils literal"><span class="pre">E</span></tt>. In general <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">b</span></tt>
are assumed to be complex numbers (meaning that some transformations
familiar for positive real numbers cannot be performed automatically
with symbolic arguments). If no simplifications can be found,
<tt class="docutils literal"><span class="pre">log(x,b)</span></tt> is expanded automatically to <tt class="docutils literal"><span class="pre">log(x)/log(b)</span></tt>.</p>
<div class="admonition-evaluating-log-integer-input admonition">
<p class="first admonition-title">Evaluating <tt class="docutils literal"><span class="pre">log</span></tt>: integer input.</p>
<p class="last">If <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">b</span></tt> are both positive integers, <tt class="docutils literal"><span class="pre">log(x,</span> <span class="pre">b)</span></tt>
evaluates to an integer when exact (note that <tt class="docutils literal"><span class="pre">log(x)/log(b)</span></tt> does
not).</p>
</div>
<div class="admonition-evaluating-log-complex-input admonition">
<p class="first admonition-title">Evaluating <tt class="docutils literal"><span class="pre">log</span></tt>: complex input.</p>
<p class="last">For complex arguments, <tt class="docutils literal"><span class="pre">log(x)</span></tt> is taken to be the principal
branch of the natural logarithm, with the branch cut placed
infinitesimally below the negative real half axis.</p>
</div>
<p><tt class="docutils literal"><span class="pre">log(x)</span></tt> evaluates to an explicit value at <tt class="docutils literal"><span class="pre">x</span></tt> = <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">E</span></tt>,
<tt class="docutils literal"><span class="pre">I</span></tt> and <tt class="docutils literal"><span class="pre">-I</span></tt>. <tt class="docutils literal"><span class="pre">log(0)</span></tt> evaluates to <tt class="docutils literal"><span class="pre">-oo</span></tt> and <tt class="docutils literal"><span class="pre">log(oo)</span></tt>
evaluates to <tt class="docutils literal"><span class="pre">oo</span></tt>.</p>
<div class="admonition-evaluating-log-power-input admonition">
<p class="first admonition-title">Evaluating <tt class="docutils literal"><span class="pre">log</span></tt>: power input.</p>
<p class="last"><tt class="docutils literal"><span class="pre">log(b**x,</span> <span class="pre">b)</span></tt> evaluates to <tt class="docutils literal"><span class="pre">x</span></tt> if <tt class="docutils literal"><span class="pre">b</span></tt> is positive and <tt class="docutils literal"><span class="pre">x</span></tt>
is real (in particular, if <tt class="docutils literal"><span class="pre">b</span></tt> is <tt class="docutils literal"><span class="pre">E</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> is rational).
By extension, <tt class="docutils literal"><span class="pre">log(b**x,</span> <span class="pre">b**y)</span></tt> evaluates to <tt class="docutils literal"><span class="pre">x/y</span></tt> if <tt class="docutils literal"><span class="pre">b</span></tt> is
positive and <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> are both real.</p>
</div>
<p>TODO: log(-x), log(I*x), log(-I*x), ...</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id13" id="trigonometric-functions" name="trigonometric-functions">4.4&nbsp;&nbsp;&nbsp;Trigonometric functions</a></h2>
<p>Trigonometric functions are automatically evaluated to algebraic
values if the argument is an integral multiple of <tt class="docutils literal"><span class="pre">pi/6</span></tt>.  (Direct
evaluation is currently also performed at all multiples of <tt class="docutils literal"><span class="pre">pi/12</span></tt>;
this behavior could be adjusted.) The poles in <tt class="docutils literal"><span class="pre">tan</span></tt> and <tt class="docutils literal"><span class="pre">cot</span></tt>
evaluate to <tt class="docutils literal"><span class="pre">zoo</span></tt>. Trigonometric functions are kept unevaluated at
<tt class="docutils literal"><span class="pre">-oo</span></tt> and <tt class="docutils literal"><span class="pre">oo</span></tt> (this can be useful when computing limits).</p>
<p>If the argument to a trigonometric function contains an explicit
rational multiple of <tt class="docutils literal"><span class="pre">pi</span></tt> as a term, this term is replaced by
a multiple of pi in the interval <tt class="docutils literal"><span class="pre">[0,</span> <span class="pre">pi/2)</span></tt> using
trigonometric identities. This may involve replacing a sine
by a cosine, etc.</p>
<p>Explicit signs are moved out of the function, e.g.
<tt class="docutils literal"><span class="pre">sin(-x)</span> <span class="pre">-&gt;</span> <span class="pre">-sin(x)</span></tt>. If the argument is a sum of several terms,
a sign is moved out if and only if all terms have an explicit
minus sign.</p>
<p>Trigonometric functions of products containing an explicit
imaginary factor <tt class="docutils literal"><span class="pre">I</span></tt> evaluate to hyperbolic functions and vice versa.</p>
</div>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id14" id="references" name="references">5&nbsp;&nbsp;&nbsp;References</a></h1>
<p><a class="reference" href="http://code.google.com/p/sympycore/wiki/ExtendedNumbers">http://code.google.com/p/sympycore/wiki/ExtendedNumbers</a></p>
</div>
</div>
</body>
</html>
